package com.gitee.poi.plugin.core.handler;

import com.gitee.poi.plugin.annotations.data.DateFormat;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Sheet;

import java.lang.reflect.Field;

public class DataFormatProcessor extends AbstractProcessor implements HandlerAnnotation {

    private Class supportAnnotation = DateFormat.class;

    public CellStyle process(Font font, CellStyle style, Sheet sheet, Field field) {
        DateFormat dateFormat = field.getDeclaredAnnotation(DateFormat.class);
        style.setDataFormat(sheet.getWorkbook().createDataFormat().getFormat(dateFormat.value()));
        return style;
    }

    public Class getSupportAnnotation() {
        return supportAnnotation;
    }
}
